Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix e2e tests #99

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open

fix: fix e2e tests #99

wants to merge 13 commits into from

Conversation

jahabeebs
Copy link
Collaborator

@jahabeebs jahabeebs commented Nov 26, 2024

🤖 Linear

Closes GRT-253

Description

  • Fixed logger issue by getting the instance before each test
  • e2e test file changes: fixed matcher logic for proper comparison between chain IDs and where we are accessing block #, added horizonStaking, separated out steps leading up authorizing a service provider and separated out service provider/operator logic from other account setup logic, added accessControl changes, added a lot more type guards to prevent casting
  • Chained logic in getAvailableChains to handle hashed array of bytes32 chain IDs (before only handling non-hashed ones incorrectly)
  • Added logic in isAuthorized to skip authorization check if operator address is same as serviceProviderAddress

Remaining items

  • Basic flow test is working but the other tests are broken (certain events like DisputeStatusUpdated not emitted)

@jahabeebs jahabeebs self-assigned this Nov 26, 2024
Copy link

linear bot commented Nov 29, 2024

@jahabeebs jahabeebs marked this pull request as ready for review December 2, 2024 04:04
@jahabeebs jahabeebs requested a review from 0xyaco December 2, 2024 04:04
Copy link
Collaborator

@0xyaco 0xyaco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wait for the other tests to be fixed prior reviewing them! Just reviewed the basic flow and the non-test code

Comment on lines 242 to 246
return encodeFunctionData({
abi: parseAbi(["function approve(address spender, uint256 amount)"]),
args: [spender, amount],
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After writing the first version of this file, I've come to learn that viem provides a standard ERC20 ABI erc20Abi value within the library.

Wdyt about using the erc20Abi (source) value provided by viem instead of hardcoding the functions whenever we are calling some ERC20 function?

for (const account of accounts) {
console.log(`Approving GRT txs on ${account.address} to ${horizonStaking}`);
// Stake GRT for other accounts
for (const account of otherAccounts) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like you could also include the service provider account here

Suggested change
for (const account of otherAccounts) {
for (const account of [...otherAccounts, serviceProvider]) {

And remove the service provider code that's been repeated below solely for the serviceProvider account.

Comment on lines 461 to 462
if (receiptSetOp.status !== "success") {
throw new Error(`Transaction failed: setOperator for ${serviceProvider.address}`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we keep this check?

*
* @returns {Record<string, Caip2ChainId>} A mapping from lowercase bytes32 hash strings to their corresponding CAIP-2 chain IDs.
*/
export function generateChainIdHashMap(): Record<string, Caip2ChainId> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check Caip2Utils.findByHash, it might work for your use case here

Comment on lines +6 to +7
import { NullNotificationService } from "@ebo-agent/automated-dispute/src/index.js";
import { RequestId, ResponseId } from "@ebo-agent/automated-dispute/src/types/index.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing from a module's .js file

@@ -102,6 +107,7 @@ describe.sequential("single agent", () => {
});

beforeEach(async () => {
Logger.getInstance();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something you had to do to avoid the tests crashing? Mind adding a comment explaining that?

Comment on lines +185 to +187
if (!accounts || accounts[0] === undefined || accounts[0]?.privateKey === undefined) {
throw new Error("Accounts not found");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which situation would the test reach this point with no accounts created? Wouldn't it fail before?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you kinda want to express that this test needs just the account[0] to be defined (as a pre-condition), an assert would convey the intention a little bit better here. Something like this:

assert(!accounts || accounts[0] === undefined, "Account not defined");
assert(accounts[0].privateKey, "Account has no private key");

Comment on lines +456 to +460
console.log("Approving bond escalation module...");
await protocolProvider.write.approveModule(
protocolContracts["BondEscalationModule"] as Address,
);
console.log("Bond escalation module approved.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be inside some of the utility functions we have?

Comment on lines +527 to +529
if (requestCreatedEvent === undefined) {
throw new Error("RequestCreated event not found");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the test reach this point with requestCreatedEvent being undefined? Wouldn't the expect right above it stop the test execution?

Comment on lines +562 to +564
if (badResponseProposedEvent === undefined) {
throw new Error("ResponseProposed event not found");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can:

Suggested change
if (badResponseProposedEvent === undefined) {
throw new Error("ResponseProposed event not found");
}
expect(badResponseProposedEvent).toBeDefined()

Right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants